package com.cheyunkeji.er.activity.evaluate;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.Constants;
import com.cheyun.netsalev3.MyApplication;
import com.cheyunkeji.er.base.BaseActivity;
import com.cheyunkeji.er.utils.ConvertUtils;
import com.cheyunkeji.er.view.TopBar;

import butterknife.BindView;
import butterknife.ButterKnife;

public class EditRemarksActivity extends BaseActivity {


    @BindView(R.id.v_topbar)
    TopBar vTopbar;
    @BindView(R.id.et_remarks)
    EditText etRemarks;
    @BindView(R.id.btn_save)
    Button btnSave;
    @BindView(R.id.activity_edit_remarks)
    LinearLayout activityEditRemarks;
    private Bundle bundle;

    public static String MULTIPLE_EDIT_LINES = "multiple_edit_lines" ;

    @Override
    protected void init() {
        setContentView(R.layout.er_activity_edit_remarks);
        ButterKnife.bind(this);
    }

    @Override
    protected void initView() {

        if (MyApplication.getInstance().getCurrentModuleType()== Constants.CURRENT_MODULE_TYPE_FAST_EVALUATE) {
            vTopbar.setBackgroundColor(getResources().getColor(R.color.bkg_blue));
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                getWindow().setStatusBarColor(getResources().getColor(R.color.bkg_blue));

        } else if (MyApplication.getInstance().getCurrentModuleType()== Constants.CURRENT_MODULE_TYPE_FULL_EVALUATE) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                getWindow().setStatusBarColor(getResources().getColor(R.color.auction_status_bar));
            vTopbar.setBackgroundColor(getResources().getColor(R.color.auction_status_bar));
        } else if (MyApplication.getInstance().getCurrentModuleType()== Constants.CURRENT_MODULE_TYPE_AUCTION) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                getWindow().setStatusBarColor(getResources().getColor(R.color.auction_status_bar));
            vTopbar.setBackgroundColor(getResources().getColor(R.color.auction_status_bar));
        }

        bundle = getIntent().getExtras();
        if (null != bundle) {
            vTopbar.setTitle(bundle.getString(Constants.EDITING_TITLE));
        }
        vTopbar.setLeftBack();
        btnSave.setOnClickListener(this);

    }

    @Override
    protected void initData() {

        if (null != bundle && !TextUtils.isEmpty(bundle.getString(Constants.EDITING_CONTENT))) {

            etRemarks.setText(bundle.getString(Constants.EDITING_CONTENT));

        }

    }

    @Override
    protected void onResume() {
        super.onResume();

        if( null != bundle && bundle.getBoolean(MULTIPLE_EDIT_LINES,false)){

            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) etRemarks.getLayoutParams();
            params.height = ConvertUtils.dp2px(200) ;
            etRemarks.setLayoutParams(params);
            etRemarks.setSingleLine(false);
        }

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v.getId() == R.id.btn_save) {
            Intent intent = new Intent();
            intent.putExtra(Constants.EDITED_CONTENT, etRemarks.getText().toString());
            setResult(RESULT_OK, intent);
            MyApplication.getInstance().removeActivity(this.getClass());
            finish();
        }
    }
}
